#include<iostream>
using namespace std;
#include<vector>
int main(){
    vector<int> array;
    int n=0;
    int i=0;
    int j=0;
    int count=0;
    while(cin>>n){
        if(n==0){
            continue;
        }
        count=0;
        while(n>=3){
            j=n%3;
            n/=3;
            count+=n;
            n+=j;
        }
        if(n==2){
            count++;
        }
        array.push_back(count);
        i++;
        n=0;
    }
    for(int j=0;j<i;j++){
        cout<<array[j]<<endl;;
    }
    return 0;
}
